﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ChinaDynastyTours.Controls;
using ChinaDynastyTours.Helpers;
using ChinaDynastyTours.Models;
using ChinaDynastyTours.Assets;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using ChinaDynastyTours.Assets.DataSet;
using System.IO;
using System.Threading;

namespace ChinaDynastyTours.Views
{
    public partial class BatchEntertainmenRestaurantOrderForm : DevExpress.XtraEditors.XtraForm
    {
        private DataTable _dtOrderData;
        
        public BatchEntertainmenRestaurantOrderForm()
        {
            InitializeComponent();
        }

        private void BatchEntertainmenRestaurantOrderForm_Load(object sender, EventArgs e)
        {
            //默认为本月1日起，下下月1日止
            dateStart.EditValue = DateTime.Parse(string.Format("{0}-{1}-01", DateTime.Now.Year, DateTime.Now.Month));
            dateEnd.EditValue = DateTime.Parse(string.Format("{0}-{1}-01", DateTime.Now.Year + DateTime.Now.Month / 11, (DateTime.Now.Month + 1) % 12 + 1));

            //初始化团下拉列表
            DataSet ds = TeamGroupCtrl.GetAllIDForTeamGroup();
            if (ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    btnTeamGroupID.Properties.Items.Add(dr["TourGroupID"].ToString().Trim());
                }
            }
            btnRefresh.PerformClick();

       }

        private void btnProviders_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Close)
            {
                DevExpress.XtraEditors.ButtonEdit btnEdit = sender as DevExpress.XtraEditors.ButtonEdit;
                btnEdit.Tag = null;
                btnEdit.EditValue = null;
            }
            else
            {
                ProviderSelectedToolForm providerForm = new ProviderSelectedToolForm();
                providerForm._ProviderTypes = new ProviderTypeEnum[] { ProviderTypeEnum.景点, ProviderTypeEnum.演出, ProviderTypeEnum.餐厅 };

                if (providerForm.ShowDialog(this) == DialogResult.OK)
                {
                    DevExpress.XtraEditors.ButtonEdit btnEdit = sender as DevExpress.XtraEditors.ButtonEdit;
                    btnEdit.Tag = providerForm.ReturnProviderID;
                    btnEdit.EditValue = providerForm.ReturnProviderName;
                }
            }
        }
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            string providerId = btnProviders.Tag == null ? "" : btnProviders.Tag.ToString();
            OrderStateEnum orderState = EnumHelper.OrderState_Str2Enum(btnOrderState.Text, true);
            _dtOrderData = EntertainmenRestaurantOrderCtrl.GetEntertainmentRestaurantOrderData(btnTeamGroupID.Text, providerId, dateStart.DateTime, dateEnd.DateTime, btnOrderID.Text,orderState);
            entertainmentGridControl.DataSource = AddGridSelectedColumn(_dtOrderData);
            InitializeGUIData();

            //SelectAllRowData(false, _dtOrderData);
        }
        private void SelectAllRowData(bool isSelectedAll, DataTable dataSource)
        {
            foreach (DataRow dr in dataSource.Rows)
                dr["Selected"] = isSelectedAll;
        }
        private void InitializeGUIData()
        {
            if (_dtOrderData != null && _dtOrderData.Rows.Count > 0)
            {
                //清除已有绑定
                tbAdultNum.DataBindings.Clear();
                tbChildNum.DataBindings.Clear();
                tbAccompanyNum.DataBindings.Clear();
                tbAdultUnitPrice.DataBindings.Clear();
                tbChildUnitPrice.DataBindings.Clear();
                tbAccompanyUnitPrice.DataBindings.Clear();

                tbOthersCost.DataBindings.Clear();
                tbCiceroniName.DataBindings.Clear();
                tbCiceroniPhone.DataBindings.Clear();
                tbProviderName.DataBindings.Clear();
                tbRemark.DataBindings.Clear();
                tbServiceName.DataBindings.Clear();
                tbTotalPrice.DataBindings.Clear();

                //与UI绑定
                this.tbAdultNum.DataBindings.Add("EditValue", _dtOrderData, "AdultNum");
                this.tbChildNum.DataBindings.Add("EditValue", _dtOrderData, "ChildNum");
                this.tbAccompanyNum.DataBindings.Add("EditValue", _dtOrderData, "AccompanyNum");
                this.tbAdultUnitPrice.DataBindings.Add("EditValue", _dtOrderData, "AdultUnitPrice");
                this.tbChildUnitPrice.DataBindings.Add("EditValue", _dtOrderData, "ChildUnitPrice");
                this.tbAccompanyUnitPrice.DataBindings.Add("EditValue", _dtOrderData, "AccompanyUnitPrice");

                this.tbOthersCost.DataBindings.Add("EditValue", _dtOrderData, "OthersCost");
                this.tbCiceroniName.DataBindings.Add("EditValue", _dtOrderData, "CiceroniName");
                this.tbCiceroniPhone.DataBindings.Add("EditValue", _dtOrderData, "CiceroniPhone");
                this.tbProviderName.DataBindings.Add("EditValue", _dtOrderData, "ProviderName");
                this.tbProviderName.DataBindings.Add("Tag", _dtOrderData, "ProviderID");
                this.tbRemark.DataBindings.Add("EditValue", _dtOrderData, "Remark");
                this.tbServiceName.DataBindings.Add("EditValue", _dtOrderData, "ServiceName");
                this.tbTotalPrice.DataBindings.Add("EditValue", _dtOrderData, "Budget");

                btnSave.Enabled = true;
            }
            else
                btnSave.Enabled = false;
        }

        private void btnCalculationPrice_Click(object sender, EventArgs e)
        {
            tbTotalPrice.EditValue = int.Parse(tbAdultNum.Text) * decimal.Parse(tbAdultUnitPrice.EditValue.ToString()) +
                                     int.Parse(tbChildNum.Text) * decimal.Parse(tbChildUnitPrice.EditValue.ToString()) +
                                     int.Parse(tbAccompanyNum.Text) * decimal.Parse(tbAccompanyUnitPrice.EditValue.ToString()) +
                                     //int.Parse(tbChildNum.Text) * decimal.Parse(tbAccompanyUnitPrice.EditValue.ToString()) +
                                     decimal.Parse(tbOthersCost.EditValue.ToString());
        }

        private void btnNumSinglePrice_Changed(object sender, EventArgs e)
        {
            tbTotalPrice.EditValue = int.Parse(tbAdultNum.Text) * decimal.Parse(tbAdultUnitPrice.EditValue.ToString()) +
                                     int.Parse(tbChildNum.Text) * decimal.Parse(tbChildUnitPrice.EditValue.ToString()) +
                                     int.Parse(tbAccompanyNum.Text) * decimal.Parse(tbAccompanyUnitPrice.EditValue.ToString()) +
                //int.Parse(tbChildNum.Text) * decimal.Parse(tbAccompanyUnitPrice.EditValue.ToString()) +
                                     decimal.Parse(tbOthersCost.EditValue.ToString());
        }

        #region 保存修改
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (_dtOrderData == null || _dtOrderData.Rows.Count == 0) return;

            DataRowView drv = (BindingContext[_dtOrderData].Current as DataRowView);

            int providerId = tbProviderName.Tag == null ? -1 : int.Parse(tbProviderName.Tag.ToString());
            string providerName = tbProviderName.Text;
            string typeBelong;
            int expenseTypeID;
            string expenseType;

            string providerType = BaseInfoCtrl.GetProviderTypeById(providerId);
                if (providerType.IndexOf(ProviderTypeEnum.景点.ToString()) > -1)
                {
                    typeBelong = ProviderTypeEnum.景点.ToString();
                    expenseTypeID = 5;//所属费用类型(费用类型表中存储着编号，此编号是固定的，1房费、2团费、3餐费、4交通费、5门票、6杂费)
                    expenseType = BaseInfoCtrl.GetExpenseTypeNameByID(5);//同上
                }
                else if (providerType.IndexOf(ProviderTypeEnum.演出.ToString()) > -1)
                {
                    typeBelong = ProviderTypeEnum.演出.ToString();
                    expenseTypeID = 5;//同上
                    expenseType = BaseInfoCtrl.GetExpenseTypeNameByID(5);//同上
                }
                else 
                {
                    typeBelong = ProviderTypeEnum.餐厅.ToString();
                    expenseTypeID = 3;//同上
                    expenseType = BaseInfoCtrl.GetExpenseTypeNameByID(3);//同上
                }
                //如果某供应商同时为演出和餐厅，此判断会不准确。
                //一个供应商属于多个类型，是为了解决“一个供应商提供多种服务，但付款和财务统计需要统一”的问题
                //但一个供应商提供多种服务的情况很少，此解决方案是否合适。。。

            
            
            EntertainmenRestaurantOrderEntity order = new EntertainmenRestaurantOrderEntity();

            order.EntertainmentOrderID = int.Parse(drv["EntertainmentOrderID"].ToString());/*重点字段*/
            order.ExpenseID = int.Parse(drv["ExpenseID"].ToString());

            order.OrderState = drv["OrderState"].ToString();/*重点内容，初始化订单状态为‘未定’*/
            order.TourgroupID = drv["TourgroupID"].ToString();
            order.TourgroupName = drv["TourgroupName"].ToString();

            order.ProviderID = providerId;
            order.ProviderName = providerName;

            order.LocalPlanScheduleID = int.Parse(drv["LocalPlanScheduleID"].ToString());
            order.ServiceDate = DateTime.Parse(drv["ServiceDate"].ToString()).ToString("yyyy-MM-dd");
            order.AdultNum = int.Parse(tbAdultNum.Text); //变更字段
            order.AdultUnitPrice = decimal.Parse(tbAdultUnitPrice.EditValue.ToString()); //变更字段
            order.ChildNum = int.Parse(tbChildNum.Text);//变更字段
            order.ChildUnitPrice = decimal.Parse(tbChildUnitPrice.EditValue.ToString());//变更字段
            order.AccompanyNum = int.Parse(tbAccompanyNum.Text);//变更字段
            order.AccompanyUnitPrice = decimal.Parse(tbAccompanyUnitPrice.EditValue.ToString());//变更字段
            order.OthersCost = decimal.Parse(tbOthersCost.EditValue.ToString());//变更字段
            order.CiceroniPhone = tbCiceroniPhone.Text;//变更字段
            order.CiceroniName = tbCiceroniName.Text;//变更字段
            order.ServiceName = tbServiceName.Text;
            order.Remark = tbRemark.Text;//变更字段
            //order.ContractPath = drv["ContractPath"].ToString();


            ExpenseEntity expense = new ExpenseEntity()
            {
                /*这里只有Budget在界面中是可被修改的内容，其余全部用原值更新*/
                //已修改，预算、供应商、服务、类型，均可修改
                //不变化的值为什么还更新呢?我把其他不变化的值屏蔽掉了
                ExpenseID = int.Parse(drv["ExpenseID"].ToString()), /*重点字段*/
                ProviderID = providerId,
                ProviderName = providerName,
                ServiceName = tbServiceName.Text,

                Budget = decimal.Parse(tbTotalPrice.EditValue.ToString()),//变更字段
                //TourgroupID = drv["TourgroupID"].ToString(),
                //TourgroupName=drv["TourgroupName"].ToString(),
                //Remark = drv["Remark"].ToString(),
                //Status = drv["Status"].ToString(),
                TypeBelong = typeBelong,
                ExpenseTypeID = expenseTypeID,
                ExpenseType = expenseType
            };

            EntertainmenRestaurantOrderCtrl.UpdateEntertainmenRestaurantOrderData(expense, order);

            //更新团审核成本
            TeamGroupCtrl.UpdateTourGroupBudgeCost(drv["TourgroupID"].ToString());

            MessageBox.Show("保存成功！", "保存数据", MessageBoxButtons.OK, MessageBoxIcon.Information);
            
            //刷新界面，因希望保存后，列表焦点行不变，于是不刷新界面。缺点是不能实时刷新，要换一行才发现变化。
            //btnRefresh.PerformClick();
            entertainmentGridView.SetFocusedRowCellValue("Budget", tbTotalPrice.EditValue.ToString());
            entertainmentGridView.SetFocusedRowCellValue("ApplyPay", decimal.Parse(tbTotalPrice.EditValue.ToString()) - decimal.Parse(entertainmentGridView.GetFocusedRowCellValue("ApplyPayTotal").ToString()));
            entertainmentGridView.SetFocusedRowCellValue("AdultNum", tbAdultNum.EditValue.ToString());
            entertainmentGridView.SetFocusedRowCellValue("ChildNum", tbChildNum.EditValue.ToString());
            entertainmentGridView.SetFocusedRowCellValue("AccompanyNum", tbAccompanyNum.EditValue.ToString());
            entertainmentGridView.SetFocusedRowCellValue("AdultUnitPrice", tbAdultUnitPrice.EditValue.ToString());
            entertainmentGridView.SetFocusedRowCellValue("CiceroniName",tbCiceroniName.EditValue.ToString());
            entertainmentGridView.SetFocusedRowCellValue("CiceroniPhone", tbCiceroniPhone.EditValue.ToString());
            drv.Row.AcceptChanges();
        }
        #endregion

        #region 提交审核处理
        /// <summary>
        /// 提交审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExpenseSubmit_Click(object sender, EventArgs e)
        {
            if (_dtOrderData == null || _dtOrderData.Rows.Count <= 0) return;

            if (MessageBox.Show("您确认提交选中内容进行审核吗？", "打印", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //entertainmentGridView.ClearSelection();
                int[] rowIds = MutilRow(entertainmentGridView);
                string expenseId = "", status="";

                foreach (int id in rowIds)
                {
                    //tourgroupId = entertainmentGridView.GetRowCellValue(id, "TourgroupID").ToString();
                    ////审核状态后的不能提交审核
                    //TeamStateEnum state = TeamGroupCtrl.GetTourGroupState(tourgroupId);
                    //if (state == TeamStateEnum.审核 || state == TeamStateEnum.终结)
                    //{
                    //    msg.Clear();
                    //    msg.AppendText(string.Format("计划号：{0}的团状态为‘{1}’，不能提交审核", tourgroupId,state));
                    //    messageDockPanel.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
                    //    return;
                    //}
                    status = entertainmentGridView.GetRowCellValue(id, "Status").ToString();
                    if (status == ExpenseStatusEnum.计划.ToString() || status == ExpenseStatusEnum.导游报销.ToString())
                    {
                        expenseId = entertainmentGridView.GetRowCellValue(id, "ExpenseID").ToString();
                        ExpensesCtrl.UpdateExpenseStatusData(expenseId, ExpenseStatusEnum.待审核);

                        entertainmentGridView.SetRowCellValue(id, "Status", ExpenseStatusEnum.待审核);
                    }
                }
                MessageBox.Show("提交完毕！", "提交审核", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        #endregion

        #region 预订信息预览、打印事件处理
        /// <summary>
        /// 打印预览
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPreview_Click(object sender, EventArgs e)
        {
            //entertainmentGridView.ClearSelection();
            int[] rowIds = MutilRow(entertainmentGridView);

            if (rowIds.Length == 0) return;

            //获取供应商名称列表及选择的数据行数据
            string providerNames = "";
            string providerId = entertainmentGridView.GetRowCellValue(rowIds[0], "ProviderID").ToString();
            EntertainmenRestaurantOrderDataSet ds = new EntertainmenRestaurantOrderDataSet();

            for (int i = 0; i < rowIds.Length; i++)
            {
                if (entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderID").ToString() != providerId)
                {
                    MessageBox.Show("所选供应商不相同", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                
                if (entertainmentGridView.GetRowCellValue(rowIds[i],"Status").ToString() != OrderStateEnum.取消.ToString())
                    ds.Tables["EntertainmenRestaurantOrder"].ImportRow(entertainmentGridView.GetDataRow(rowIds[i]));

                //if (entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName") != null && !providerNames.Contains(entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName").ToString()) && entertainmentGridView.GetRowCellValue(rowIds[i], "Status").ToString() != ExpenseStatusEnum.取消.ToString())
                //    providerNames = string.Format("{0}　{1}", providerNames, entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName"));
            }

            ProviderEntity provider = BaseInfoCtrl.GetProviderDataByID(providerId);
            providerNames = string.Format("{0}\t联系人：{1}\t传真：{2}\t电话：{3}", provider.ProviderName, provider.Contact, provider.fax, provider.Telephone);

            EntertainmenRestaurantOrderReport rpt = new EntertainmenRestaurantOrderReport(providerNames);
            rpt.DataSource = ds;
            //new PrintPreviewForm(rpt, "").ShowDialog();
            rpt.ShowPreviewDialog();
        }
        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            //entertainmentGridView.ClearSelection();
            int[] rowIds = MutilRow(entertainmentGridView);

            if (rowIds.Length == 0) return;

            if (MessageBox.Show("您确认打印选中的娱乐餐单信息吗？", "打印", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //获取供应商名称列表及选择的数据行数据
                string providerNames = "";
                string providerId = entertainmentGridView.GetRowCellValue(rowIds[0], "ProviderID").ToString();
                EntertainmenRestaurantOrderDataSet ds = new EntertainmenRestaurantOrderDataSet();

                for (int i = 0; i < rowIds.Length; i++)
                {
                    if (entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderID").ToString() != providerId)
                    {
                        MessageBox.Show("所选供应商不相同", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    if (entertainmentGridView.GetRowCellValue(rowIds[i], "Status").ToString() != OrderStateEnum.取消.ToString())
                        ds.Tables["EntertainmenRestaurantOrder"].ImportRow(entertainmentGridView.GetDataRow(rowIds[i]));

                    //if (entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName") != null && !providerNames.Contains(entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName").ToString()) && entertainmentGridView.GetRowCellValue(rowIds[i], "Status").ToString() != ExpenseStatusEnum.取消.ToString())
                    //    providerNames = string.Format("{0}　{1}", providerNames, entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName"));
                }

                ProviderEntity provider = BaseInfoCtrl.GetProviderDataByID(providerId);
                providerNames = string.Format("{0}\t联系人：{1}\t传真：{2}\t电话：{3}", provider.ProviderName, provider.Contact, provider.fax, provider.Telephone);
                
                EntertainmenRestaurantOrderReport rpt = new EntertainmenRestaurantOrderReport(providerNames);
                rpt.DataSource = ds;
                if (rpt.PrintDialog() == DialogResult.OK)//打印完毕之后将订单状态变为‘已定’
                {
                    string entertainmentOrderID = "";
                    foreach (int id in rowIds)
                    {
                        if (entertainmentGridView.GetRowCellValue(id, "Status").ToString() != OrderStateEnum.取消.ToString())
                        {
                            entertainmentOrderID = entertainmentGridView.GetRowCellValue(id, "EntertainmentOrderID").ToString();
                            EntertainmenRestaurantOrderCtrl.UpdateEntertainmenRestauranOrderStateData(entertainmentOrderID, OrderStateEnum.已订);
                            entertainmentGridView.SetRowCellValue(id, "OrderState", OrderStateEnum.已订);
                        }
                    }
                    MessageBox.Show("打印完毕！", "打印", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        /// <summary>
        /// 发送EMail
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEmail_Click(object sender, EventArgs e)
        {
            if (_dtOrderData == null || _dtOrderData.Rows.Count <= 0) return;

            #region 生成报表
            //entertainmentGridView.ClearSelection();
            int[] rowIds = MutilRow(entertainmentGridView);

            if (rowIds.Length == 0)
            {
                MessageBox.Show("没有选择“发送内容”，请勾选‘选择’项", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            } 

            //获取供应商名称列表及选择的数据行数据
            string providerNames = "";
            string providerId = entertainmentGridView.GetRowCellValue(rowIds[0], "ProviderID").ToString();
            EntertainmenRestaurantOrderDataSet ds = new EntertainmenRestaurantOrderDataSet();

            for (int i = 0; i < rowIds.Length; i++)
            {
                if (entertainmentGridView.GetRowCellValue(rowIds[i], "Status").ToString() != OrderStateEnum.取消.ToString())
                    ds.Tables["EntertainmenRestaurantOrder"].ImportRow(entertainmentGridView.GetDataRow(rowIds[i]));

                //if (entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName") != null && !providerNames.Contains(entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName").ToString()) && entertainmentGridView.GetRowCellValue(rowIds[i], "Status").ToString() != ExpenseStatusEnum.取消.ToString())
                //    providerNames = string.Format("{0}　{1}", providerNames, entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderName"));
            }
 
            ProviderEntity provider = BaseInfoCtrl.GetProviderDataByID(providerId);
            providerNames = string.Format("{0}\t联系人：{1}\t传真：{2}\t电话：{3}", provider.ProviderName, provider.Contact, provider.fax, provider.Telephone);

            EntertainmenRestaurantOrderReport rpt = new EntertainmenRestaurantOrderReport(providerNames);
            rpt.DataSource = ds;

            #endregion

            #region 发送EMail

            //ProviderEntity entity;
            //StringBuilder info = new StringBuilder();
            List<string> receiveMail = new List<string>();
            //StringBuilder recipients = new StringBuilder();

                string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "演出餐厅预订单.pdf");
                rpt.ExportToPdf(file);
                if (File.Exists(file))
                {
                    string ReplyAddress = SysParameterCtrl.GetValueForKey("ScheduleMailAddress"); 
                    //string ServerMailAddress = SysParameterCtrl.GetValueForKey("TicketMailServer");
                    //string ServerMailPassword = SysParameterCtrl.GetValueForKey("TicketMailPassword");
                    //string ServerMailSmtp = SysParameterCtrl.GetValueForKey("TicketMailSmtp");
                    List<string> files = new List<string>();
                    //string title = "娱乐餐单预订";
                    files.Add(file);
                    
                    string providerID = entertainmentGridView.GetRowCellValue(rowIds[0], "ProviderID").ToString();
                    if (string.IsNullOrEmpty(providerID) || providerID == "-1")
                    {
                        MessageBox.Show("尚未确定供应商", "信息提示");
                        return;
                    }

                    //ProviderEntity provider = BaseInfoCtrl.GetProviderDataByID(providerID);
                    string emailAddress = provider.email.ToString();
                    string recipients = entertainmentGridView.GetRowCellValue(rowIds[0], "ProviderName").ToString();
                    
                    if (string.IsNullOrEmpty(emailAddress) || (emailAddress.IndexOf("@") < 1) || (emailAddress.Substring(emailAddress.IndexOf("@")).IndexOf(".") < 2))
                    {
                        MessageBox.Show("当前接收人地址格式不正确", "信息提示");
                        return;
                    }

                    for (int i = 1; i < rowIds.Length; i++)
                    {
                        if (providerID != entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderID").ToString())
                        {
                            MessageBox.Show("请选择同一收件人", "信息提示");
                            return;
                        }
                    }
                    receiveMail.Add(emailAddress);

                    if (EMailHelper.SendMail(receiveMail, "演出餐厅预订", "请收到此通知后回复确认。\r\n\r\n北京龙润国际旅行社有限公司", files, ReplyAddress, recipients, "", "", LogTypeEnum.计调类))
                    {
                        MessageBox.Show("邮件发送成功！", "信息提示");
                        string entertainmentOrderID = "";
                        foreach (int id in rowIds)
                        {
                            if (entertainmentGridView.GetRowCellValue(id, "Status").ToString() != OrderStateEnum.取消.ToString())
                            {
                                entertainmentOrderID = entertainmentGridView.GetRowCellValue(id, "EntertainmentOrderID").ToString();
                                EntertainmenRestaurantOrderCtrl.UpdateEntertainmenRestauranOrderStateData(entertainmentOrderID, OrderStateEnum.已订);
                                entertainmentGridView.SetRowCellValue(id, "OrderState", OrderStateEnum.已订);
                            }
                        }

                    }
                    else
                        MessageBox.Show("邮件发送失败，详情请查看日志", "信息提示");
                    File.Delete(file);
                }
                else
                {
                    MessageBox.Show("发送失败,生成报表文件失败！", "信息提示");
                }

           #endregion
        }
        #endregion

        #region 增加处理

        private void addRestaurant_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            if (btnTeamGroupID.Text == "")
            {
                MessageBox.Show("您还没有选择‘计划号’！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DataTable dtTourgroup = TeamGroupCtrl.GetTeamGroupRowData(btnTeamGroupID.Text);

            if (dtTourgroup.Rows[0]["TourgroupState"].ToString() != TeamStateEnum.成行.ToString() && dtTourgroup.Rows[0]["TourgroupState"].ToString() != TeamStateEnum.分配.ToString())
            {
                MessageBox.Show(string.Format("团‘{0}’未成行或已审核，无法添加预订！", btnTeamGroupID.Text), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            int scheduleId = TeamGroupCtrl.GetFirstTourgroupScheduleID(btnTeamGroupID.Text);

            //判断当前是否有选择的团一致行程计划
            if (scheduleId < 0)
            {
                MessageBox.Show(string.Format("团‘{0}’没有安排行程计划，无法添加预订！", btnTeamGroupID.Text), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DataTable dtLocalPanSchedule = LocalTeamGroupCtrl.GetLocalPlanSchedule(btnTeamGroupID.Text, 1);
            if (dtLocalPanSchedule.Rows.Count < 1)
            {
                MessageBox.Show(string.Format("团‘{0}’没有本地行程计划，无法添加预订！", btnTeamGroupID.Text), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }


            RestaurantOrderForm enterRestOrderForm = new RestaurantOrderForm()
            {
                _TourGroupID = btnTeamGroupID.Text,
                _LocalPlanScheduleDate = dtLocalPanSchedule.Rows[0]["Date"].ToString(),
                _LocalPlanScheduleID = dtLocalPanSchedule.Rows[0]["LocalPlanScheduleID"].ToString(),
                _TourGroupScheduleID = scheduleId.ToString(),
                _AdultNum = int.Parse(dtTourgroup.Rows[0]["AdultNum"].ToString()),
                _ChildNum = int.Parse(dtTourgroup.Rows[0]["ChildNum"].ToString()),
                //_AccompanyNum = tbAccompanyNum.EditValue == DBNull.Value ? 0 : int.Parse(tbAccompanyNum.EditValue.ToString())
            };
            enterRestOrderForm.ShowDialog(this);

            btnRefresh.PerformClick();

        }

        private void addEntertainment_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (btnTeamGroupID.Text == "")
            {
                MessageBox.Show("您还没有选择‘计划号’！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DataTable dtTourgroup = TeamGroupCtrl.GetTeamGroupRowData(btnTeamGroupID.Text);

            if (dtTourgroup.Rows[0]["TourgroupState"].ToString() != TeamStateEnum.成行.ToString() && dtTourgroup.Rows[0]["TourgroupState"].ToString() != TeamStateEnum.分配.ToString())
            {
                MessageBox.Show(string.Format("团‘{0}’未成行或已审核，无法添加预订！", btnTeamGroupID.Text), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            int scheduleId = TeamGroupCtrl.GetFirstTourgroupScheduleID(btnTeamGroupID.Text);

            //判断当前是否有选择的团一致行程计划
            if (scheduleId < 0)
            {
                MessageBox.Show(string.Format("团‘{0}’没有安排行程计划，无法添加预订！", btnTeamGroupID.Text), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DataTable dtLocalPanSchedule = LocalTeamGroupCtrl.GetLocalPlanSchedule(btnTeamGroupID.Text, 1);
            if (dtLocalPanSchedule.Rows.Count < 1)
            {
                MessageBox.Show(string.Format("团‘{0}’没有本地行程计划，无法添加预订！", btnTeamGroupID.Text), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            EntertainmenOrderForm enterRestOrderForm = new EntertainmenOrderForm(0)
            {
                _TourGroupID = btnTeamGroupID.Text,
                _LocalPlanScheduleDate = dtLocalPanSchedule.Rows[0]["Date"].ToString(),
                _LocalPlanScheduleID = dtLocalPanSchedule.Rows[0]["LocalPlanScheduleID"].ToString(),
                _TourGroupScheduleID = scheduleId.ToString(),
                _AdultNum = int.Parse(dtTourgroup.Rows[0]["AdultNum"].ToString()),
                _ChildNum = int.Parse(dtTourgroup.Rows[0]["ChildNum"].ToString()),
                //_AccompanyNum = tbAccompanyNum.EditValue == DBNull.Value ? 0 : int.Parse(tbAccompanyNum.EditValue.ToString())
            };
            enterRestOrderForm.ShowDialog(this);

            btnRefresh.PerformClick();

        }
        #endregion 
        
        #region 取消处理
        /// <summary>
        /// 取消处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if ((entertainmentGridView.GetRowCellValue(entertainmentGridView.FocusedRowHandle, "Status").ToString() != ExpenseStatusEnum.计划.ToString()
             && entertainmentGridView.GetRowCellValue(entertainmentGridView.FocusedRowHandle, "Status").ToString() != ExpenseStatusEnum.导游报销.ToString())
             || entertainmentGridView.GetRowCellValue(entertainmentGridView.FocusedRowHandle, "PayStatus").ToString() != PayApplyStatusEnum.未付.ToString())
            {
                MessageBox.Show("该预订已支付或提交审核，不能取消！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("确定取消选中的预订信息吗？", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                string expenseId = entertainmentGridView.GetRowCellValue(entertainmentGridView.FocusedRowHandle, "ExpenseID").ToString();
                string entertainmentOrderID = entertainmentGridView.GetRowCellValue(entertainmentGridView.FocusedRowHandle, "EntertainmentOrderID").ToString();
                string tourgroupId = entertainmentGridView.GetRowCellValue(entertainmentGridView.FocusedRowHandle, "TourgroupID").ToString();

                ExpensesCtrl.UpdateExpenseStatusData(expenseId, ExpenseStatusEnum.取消);
                EntertainmenRestaurantOrderCtrl.UpdateEntertainmenRestauranOrderStateData(entertainmentOrderID, OrderStateEnum.取消);

                //更新团审核成本
                TeamGroupCtrl.UpdateTourGroupBudgeCost(tourgroupId);

                //刷新
                entertainmentGridView.SetRowCellValue(entertainmentGridView.FocusedRowHandle, "Status", ExpenseStatusEnum.取消);
                entertainmentGridView.SetRowCellValue(entertainmentGridView.FocusedRowHandle, "OrderState", OrderStateEnum.取消);
            }

        }
        #endregion

        #region 打印结算单
        /// <summary>
        /// 打印结算单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrintClearingBill_Click(object sender, EventArgs e)
        {
            decimal totalpayment;
            string providerID;
            int[] rowIds;

            //校验选择内容数据
            if (!ValidateData(out totalpayment, out providerID, out rowIds))
                return;

            if (sender.Equals(btnPrintClearingBill))
            {
                if (DialogResult.Yes == MessageBox.Show("请注意，本次打印的同时将会一并发送申请单到财务，过程不可逆，是否确认？", "打印确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    //任选一项提取供应商信息
                    ProviderEntity provider = BaseInfoCtrl.GetProviderDataByID(providerID);
                    if (provider != null)
                    {
                        #region 生成付款申请单和付款申请单详情数据
                        string currentUser = UserInfoCtrl.GetNameByUserName(Thread.CurrentPrincipal.Identity.Name);//当前登录者

                        //准备付款申请单数据
                        PayApplyEntity payApplyEntity = new PayApplyEntity()
                        {
                            //PayApplyID = ,
                            ProviderName = provider.ProviderName,
                            ProviderID = provider.ProviderID,
                            Contact = "",//tbContact.Text,
                            Telephone = provider.Telephone,
                            Fax = provider.fax,
                            TotalpaymentG = MoneyHelper.ChMoney(totalpayment),
                            TotalpaymentL = totalpayment,
                            Applicants = currentUser,
                            Audit = "",
                            PlanPayTime = provider.IsSigned == 1 ? "月结" : "",//是月结供应商则‘月结’，否则提供拟汇款时间
                            ApplyPayTime = DateTime.Today.ToString("yyyy-MM-dd"),//申请时间
                            PayTime = "",//财务付款时间
                            PayStatus = PayStatusEnum.未付.ToString(),
                            Remark = currentUser + " 申请 " + provider.ProviderName + " 费用"
                        };

                        //准备付款详情数据
                        string[] providerIds = new string[rowIds.Length];
                        PayDetailEntity[] payDetailEntity = new PayDetailEntity[rowIds.Length];

                        for (int i = 0; i < rowIds.Length; i++)//为每一条数据创建一条付款详情信息——供历史查询
                        {
                            payDetailEntity[i] = new PayDetailEntity();
                            //entity[i].PayApplyID = payApplyId;
                            payDetailEntity[i].ExpenseID = int.Parse(entertainmentGridView.GetRowCellValue(rowIds[i], "ExpenseID").ToString());
                            payDetailEntity[i].ApplyPay = decimal.Parse(entertainmentGridView.GetRowCellValue(rowIds[i], "ApplyPay").ToString());//将申请额，一次性申请
                            payDetailEntity[i].PayStatus = PayDetailStatusEnum.未付.ToString();
                        }
                        //写入付款单及付款详情数据
                        string payApplyId = PayApplyCtrl.CreatePayApplyAndPayDetailData(payApplyEntity, payDetailEntity);

                        #endregion

                        #region 写入费用表中‘已申请总额’

                        Dictionary<int, decimal> data = new Dictionary<int, decimal>();
                        Dictionary<int, string> tourGroupIds = new Dictionary<int, string>();

                        for (int i = 0; i < rowIds.Length; i++)
                        {
                            //DataRowView drv = BindingContext[_dtPayApply].Current as DataRowView;
                            decimal applyPay = entertainmentGridView.GetRowCellValue(rowIds[i], "ApplyPay").ToString() == "" ? 0 : decimal.Parse(entertainmentGridView.GetRowCellValue(rowIds[i], "ApplyPay").ToString());//本次申请额
                            decimal applyPayTotal = entertainmentGridView.GetRowCellValue(rowIds[i], "ApplyPayTotal").ToString() == "" ? 0 : decimal.Parse(entertainmentGridView.GetRowCellValue(rowIds[i], "ApplyPayTotal").ToString());//已申请总额
                            int expenseId = int.Parse(entertainmentGridView.GetRowCellValue(rowIds[i], "ExpenseID").ToString());
                            string tourGroupId = entertainmentGridView.GetRowCellValue(rowIds[i], "TourgroupID").ToString();

                            entertainmentGridView.SetRowCellValue(rowIds[i], "ApplyPayTotal", applyPayTotal + applyPay);//更新界面‘已申请总额’单元格
                            data.Add(expenseId, applyPayTotal + applyPay);

                            tourGroupIds.Add(expenseId, tourGroupId);

                            ExpensesCtrl.UpdateExpenseApplyPayTotal(expenseId);
                        }

                        //更新团实际成本
                        TeamGroupCtrl.UpdateTourGroupRealCostbyGourpIDs(tourGroupIds);

                        #endregion

                        #region 提交审核

                        string status="";

                        foreach (int id in rowIds)
                        {
                            status = entertainmentGridView.GetRowCellValue(id, "Status").ToString();
                            if (status == ExpenseStatusEnum.计划.ToString() || status == ExpenseStatusEnum.导游报销.ToString())
                            {
                                ExpensesCtrl.UpdateExpenseStatusData(entertainmentGridView.GetRowCellValue(id, "ExpenseID").ToString(), ExpenseStatusEnum.待审核);

                                entertainmentGridView.SetRowCellValue(id, "Status", ExpenseStatusEnum.待审核);
                                
                            }
                            //设置费用支付状态为申请
                            ExpensesCtrl.UpdateExpensePayStatus(entertainmentGridView.GetRowCellValue(id, "ExpenseID").ToString(), PayApplyStatusEnum.申请);
                            entertainmentGridView.SetRowCellValue(id, "PayStatus", PayApplyStatusEnum.申请);
                        }

                        #endregion

                        #region 打印结算单（报表）

                        EntertainmenRestaurantOrderDataSet ds = new EntertainmenRestaurantOrderDataSet();

                        for (int i = 0; i < rowIds.Length; i++)
                            ds.Tables["EntertainmenRestaurantOrder"].ImportRow(entertainmentGridView.GetDataRow(rowIds[i]));

                        ds.Tables["fin_PayApply"].Rows.Add();
                        ds.Tables["fin_PayApply"].Rows[0]["PayApplyID"] = payApplyId;

                        EntertainmenRestaurantClearingBillReport rpt = new EntertainmenRestaurantClearingBillReport(string.Format("{0}\t联系人：{1}\t传真：{2}\t电话：{3}", provider.ProviderName, provider.Contact, provider.fax, provider.Telephone));
                        rpt.DataSource = ds;
                        rpt.ShowPreviewDialog();

                        #endregion

                    }
                }
            }
            else
            {
                //任选一项提取供应商信息
                ProviderEntity provider = BaseInfoCtrl.GetProviderDataByID(providerID);

                #region 预览结算单（报表）

                EntertainmenRestaurantOrderDataSet ds = new EntertainmenRestaurantOrderDataSet();

                for (int i = 0; i < rowIds.Length; i++)
                    ds.Tables["EntertainmenRestaurantOrder"].ImportRow(entertainmentGridView.GetDataRow(rowIds[i]));

                EntertainmenRestaurantClearingBillReport rpt = new EntertainmenRestaurantClearingBillReport(string.Format("{0}\t联系人：{1}\t传真：{2}\t电话：{3}", provider.ProviderName, provider.Contact, provider.fax, provider.Telephone));
                rpt.DataSource = ds;
                rpt.ShowPreviewDialog();

                #endregion
            }
        }
        /// <summary>
        /// 校验选择数据是否合法
        /// </summary>
        /// <param name="totalpayment">校验通过，返回本次申请额总和</param>
        /// <param name="providerID">校验通过，返回供应商ID</param>
        /// <param name="rowIds">返回所有选中的行号</param>
        /// <returns>校验是否通过</returns>
        private bool ValidateData(out decimal totalpayment, out string providerID, out int[] rowIds)
        {
            msg.Clear();

            //判断是否是同一供应商，以及本次申请费用和
            totalpayment = 0;
            providerID = "";

            //entertainmentGridView.ClearSelection();
            rowIds = MutilRow(entertainmentGridView);

            if (rowIds.Length >= 1)
            {
                providerID = entertainmentGridView.GetRowCellValue(rowIds[0], "ProviderID").ToString();
                string providerName = entertainmentGridView.GetRowCellValue(rowIds[0], "ProviderName").ToString();
                if (providerName.Trim() == "")
                {
                    msg.AppendText("尚未指定供应商，请指定供应商\r\n");
                    messageDockPanel.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
                    return false;
                }

                totalpayment = decimal.Parse(entertainmentGridView.GetRowCellValue(rowIds[0], "ApplyPay").ToString());
                for (int i = 0; i < rowIds.Length; i++)
                {
                    if (providerID != entertainmentGridView.GetRowCellValue(rowIds[i], "ProviderID").ToString())
                    {
                        msg.AppendText("选中项的各个'供应商'不完全相同，请选择相同供应商项\r\n");
                        messageDockPanel.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
                        return false;
                    }
                    if (decimal.Parse(entertainmentGridView.GetRowCellValue(rowIds[i], "ApplyPay").ToString()) == 0)
                    {
                        msg.AppendText("选择项中有'申请额'为空项,不能打印\r\n");
                        messageDockPanel.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
                        return false;
                    }
                    if (entertainmentGridView.GetRowCellValue(rowIds[i], "Status").ToString() == ExpenseStatusEnum.取消.ToString()
                        || entertainmentGridView.GetRowCellValue(rowIds[i], "Status").ToString() == ExpenseStatusEnum.终结.ToString())
                    {
                        msg.AppendText("选择项中有的费用已终结或已取消,不能打印\r\n");
                        messageDockPanel.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
                        return false;
                    }
                    string payApplyStatus = entertainmentGridView.GetRowCellValue(rowIds[i], "PayStatus").ToString();
                    if (payApplyStatus == PayApplyStatusEnum.付清.ToString())
                    {
                        //即使申请过也可再申请，只有终结后不能申请，但这个判断好像和上面的重复了。
                        msg.AppendText("选择项中费用已终结,不能打印\r\n");
                        messageDockPanel.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
                        return false;
                    }
                    if (i != 0)    //非第一行
                        totalpayment += decimal.Parse(entertainmentGridView.GetRowCellValue(rowIds[i], "ApplyPay").ToString());
                }
                return true;
            }
            msg.AppendText("没有选择任何内容，请在选择项上打‘√’\r\n");
            return false;
        }
        #endregion

        private void entertainmentGridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (BindingContext[_dtOrderData].Position == -1||e.FocusedRowHandle < 0) return;

            string tourgroupId = entertainmentGridView.GetRowCellValue(e.FocusedRowHandle, "TourgroupID").ToString();

            #region 初始化导游下拉列表

            listBoxCiceroni.DataSource = GuideArrangeCtrl.GetGuideInfoForPrint(tourgroupId);
            listBoxCiceroni.DisplayMember = "CiceroniName";
            listBoxCiceroni.ValueMember = "Phone";

            #endregion
             
            
            //审核状态后的不能新增和删除内容
            TeamStateEnum state = TeamGroupCtrl.GetTourGroupState(tourgroupId);
            if (state == TeamStateEnum.审核 || state == TeamStateEnum.终结)
                entertainmentPanel.Enabled = false;
            else
                entertainmentPanel.Enabled = true;

            //DataRowView drv = (BindingContext[_dtOrderData].Current as DataRowView);

            //lblServiceName.Enabled = drv["TypeBelong"].ToString() == ProviderTypeEnum.餐厅.ToString();
            //tbServiceName.Enabled = drv["TypeBelong"].ToString() == ProviderTypeEnum.餐厅.ToString();
        }
        /// <summary>
        /// 选择导游
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBoxCiceroni_Click(object sender, EventArgs e)
        {
            if (listBoxCiceroni.ItemCount > 0)
            {
                tbCiceroniName.EditValue = listBoxCiceroni.Text;
                tbCiceroniPhone.EditValue = listBoxCiceroni.SelectedValue.ToString();
                popupContainerControl1.OwnerEdit.ClosePopup();
            }
        }

        #region 打钩选择处理

        /// <summary>
        /// 添加‘选择’附加列
        /// </summary>
        /// <param name="dtSource"></param>
        /// <returns></returns>
        private DataTable AddGridSelectedColumn(DataTable dtSource)
        {
            dtSource.Columns.Add("Selected", typeof(bool));
            return dtSource;
        }

        private void SelectedCheckEdit_CheckedChanged(object sender, EventArgs e)
        {
            #region 打钩选择行

            //int iFocuse = entertainmentGridView.FocusedRowHandle;
            //entertainmentGridView.ClearSelection();

            //if ((sender as CheckEdit).Checked)
            //    entertainmentGridView.SelectRow(iFocuse);

            //int[] rowIds = MutilRow(entertainmentGridView);

            #endregion
        }
        private int[] MutilRow(GridView gv)
        {
            List<int> rowIds = new List<int>();
            for (int i = 0; i < gv.RowCount; i++)
            {
                object objValue = gv.GetRowCellValue(i, "Selected");
                if (objValue != null)
                {
                    bool check = false;
                    bool.TryParse(objValue.ToString(), out check);
                    if (check)
                    {
                        rowIds.Add(i);
                    }
                }
            }
            return rowIds.ToArray();

            //object selected;
            //for (int i = 0; i < gv.RowCount; i++)
            //{
            //    selected = gv.GetRowCellValue(i, "Selected");

            //    if (string.IsNullOrEmpty(selected.ToString())) continue;

            //    if (Convert.ToBoolean(selected) == true)
            //    {
            //        gv.SelectRow(i);
            //    }
            //}
            //return gv.GetSelectedRows();
        }
        #endregion
        private void entertainmentGridView_RowStyle(object sender, RowStyleEventArgs e)
        {
            if (e.RowHandle < 0) return;
            //object selected = entertainmentGridView.GetRowCellValue(e.RowHandle, "Selected");

            //if (selected == DBNull.Value) return;

            //if (Convert.ToBoolean(selected) == true)
            //{
            //    e.Appearance.BackColor = Color.Wheat;
            //    e.Appearance.BackColor2 = Color.Azure;
            //}
            //else
            //{
            //    e.Appearance.BackColor = Color.Empty;
            //    e.Appearance.BackColor2 = Color.Empty;
            //}
            object orderState = entertainmentGridView.GetRowCellValue(e.RowHandle, "OrderState");
            if (orderState.ToString() == OrderStateEnum.已订.ToString())
                e.Appearance.BackColor = Color.LightSteelBlue;
            
            object status = entertainmentGridView.GetRowCellValue(e.RowHandle, "Status");
            if (status.ToString() == ExpenseStatusEnum.导游报销.ToString())
                e.Appearance.BackColor = Color.Plum;
            else if (status.ToString() == ExpenseStatusEnum.待审核.ToString())
                e.Appearance.BackColor = Color.DarkKhaki;
            else if (status.ToString() == ExpenseStatusEnum.审核.ToString())
                e.Appearance.BackColor = Color.LightGreen;
            else if (status.ToString() == ExpenseStatusEnum.取消.ToString())
                e.Appearance.BackColor = Color.DarkOrchid;

            object payStatus = entertainmentGridView.GetRowCellValue(e.RowHandle, "PayStatus");
            if (payStatus.ToString() == PayApplyStatusEnum.申请.ToString())
                e.Appearance.BackColor = Color.DarkGreen;
            else if (payStatus.ToString() == PayApplyStatusEnum.已付.ToString())
                e.Appearance.BackColor = Color.Salmon;
            else if (payStatus.ToString() == PayApplyStatusEnum.付清.ToString())
                e.Appearance.BackColor = Color.Silver;
            }
 
        
        private void tbSelectedAll_CheckedChanged(object sender, EventArgs e)
        {

            foreach (DataRow dr in _dtOrderData.Rows)
                dr["Selected"] = tbSelectedAll.Checked;
        }


    }
}
